package com.hanamaki.unit.junit.util;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class FileUtil {
    static FileInputStream fileInputStream = null;
    static InputStreamReader inputStreamReader = null;
    static BufferedReader bufferedReader = null;

    public static Object[][] getFileContent(String filePath) {
        Object[][] result = null;
        try {
            fileInputStream = new FileInputStream(filePath);// alt + enter           ctrl + shift + enter
            inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
            bufferedReader = new BufferedReader(inputStreamReader);
            // 定义一个 存取 每一行的值的集合
            List<Object[]> list = new ArrayList<>();
            //获取 标题行
            String title = bufferedReader.readLine();
            System.out.println(title);
            String lineContent;
            while ((lineContent = bufferedReader.readLine()) != null) {
                String[] split = lineContent.split(",");
                list.add(split);
            }

            // 定义一个二维数组
            result = new Object[list.size()][];
            for (int i = 0; i < list.size(); i++) {
                result[i] = list.get(i);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedReader.close();
                inputStreamReader.close();
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

        return result;
    }



}
